const HOST = require('./config.js').host

App({
    globalData:{
        isGuide: null, // 用户是否是导游
        userInfo: null, // 用户信息
        order: {}, // 订单信息
        postage: null, // 邮费
        ceil: 100, // 

        // 带参数二维码参数
        // store: null,
        // location: null,
        // address: null
        qrcode: {} // 二维码参数
    },

    userId: '', // openid

    /**
     * 验证用户身份
     */
    verify (id) {
        let self = this

        wx.request({
            url: HOST + '' + id,
            method: 'GET',
            success (res) {
                if (res.data.sysCode === 1) {
                    self.globalData.isGuide = true
                }
            }
        })
    },

    getUserInfo(cb) {
        let self = this

        wx.login({
            success(res) {
                if (res.code) {
                    wx.request({
                        url: HOST + 'v1/login/' + res.code,
                        method: 'GET',
                        success(res) {
                            if (res.data.sysCode === 1) {
                                self.userId = res.data.data
                                // self.verify(self.userId)
                            }
                        }
                    })
                } else {
                    console.log('获取用户登录态失败！' + res.errMsg)
                }

                wx.getUserInfo({
                    success(res) {
                      
                        self.globalData.userInfo = res.userInfo
                    }
                })
            }
        })
    },

    onLaunch() {
        let self = this
        wx.request({
            url: HOST + 'v1/postage/queryPostage/0',
            method: 'GET',
            success(res) {
                if (res.data.sysCode === 1) {
                    self.globalData.ceil = res.data.data
                }
            }
        })

        this.getUserInfo()
    }
})